public class Java1002 {

        public int val;
        public Java1002 next;
        public Java1002 head;


        public Java1002(int val) {
            this.val = val;
        }

        public void creatList() {

            Java1002 node1 = new Java1002(12);
            Java1002 node2 = new Java1002(23);
            Java1002 node3 = new Java1002(34);
            Java1002 node4 = new Java1002(45);
            Java1002 node5 = new Java1002(56);


            node1.next = node2;  //将前一个结点的地址赋予给上一个结点的.next字段
            node2.next = node3;  //从而建立链接
            node3.next = node4;
            node4.next = node5;

            this.head = node1;

        }

    //计算长度
        public int size(){
            Java1002 x = head;
            int count = 0;
            while (x != null){
                count++;
                x = x.next;
            }

            return count;
        }

   //判断是否包含某个值
        public boolean contain(int key){
            Java1002 x = head;

            while (x != null){
               if(x.val == key){    //注意是x.val，x代替head往前走
                   return true;
               }
                x = x.next;
            }
            return false;
        }

        public void addFirst(int key){
            Java1002 node = new Java1002(key);

            node.next = head;      //先绑定后面的值，再确定头
            head = node;

        }

        public void show() {
            Java1002 x = head;

            while (x != null){
                System.out.println(x.val);
                x = x.next;
            }
        }


    }





